/**************************************************************
 *@ProjectName: blweibo
 *@FileName: MoreItemsActivity.java
 *@Date: 2011-5-31
 *@Copyright: 2011 www.hrbanlv.com Inc. All rights reserved.
 **************************************************************/
package com.zhiweibo;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

/**
 * The Class MoreItemsActivity.
 * 
 * @author SunHaibin
 * @since Android 1.6
 * @history 2011-5-31
 */
public class MoreItemsActivity extends HomeListBaseActivity {

    /*
     * (non-Javadoc)
     * 
     * @see com.yingnet.zhiweibo.BaseActivity#onCreate(android.os.Bundle)
     */
    @Override
    public void onCreate(Bundle paramBundle) {
        super.onCreate(paramBundle);
        setView(R.layout.moreitems);
        setTitleBar(1, null, getString(R.string.more), null);

        ArrayList<Integer> imageList1 = new ArrayList<Integer>();
        imageList1.add(R.drawable.setting);
        imageList1.add(R.drawable.moreitems_accountmanage_icon);
        imageList1.add(R.drawable.readmode_icon);
        imageList1.add(R.drawable.feedback);
        imageList1.add(R.drawable.moreitems_about_icon);
        ArrayList<String> textList1 = new ArrayList<String>();
        textList1.add(getResources().getString(R.string.menu_settings));
        textList1.add(getResources().getString(R.string.weibo_account_manage));
        textList1.add(getResources().getString(R.string.weibo_officialweibo));
        textList1.add(getResources().getString(R.string.weibo_feedback));
        textList1.add(getResources().getString(R.string.menu_about));
        MoreItemsAdapter adapter1 = new MoreItemsAdapter(this, imageList1, textList1);
        DisplayMetrics localDisplayMetrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(localDisplayMetrics);
        ListView localListView1 = (ListView) findViewById(R.id.moreItemsListView);
        localListView1.getLayoutParams().height = -1;
        localListView1.getLayoutParams().width = -1;
        localListView1.setDivider(null);
        localListView1.setAdapter(adapter1);
        localListView1.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                switch (position) {
                case 0:
                    startActivity(new Intent(MoreItemsActivity.this, SettingsPref.class));
                    break;
                case 1:
                    startActivity(new Intent(MoreItemsActivity.this, AccountManager.class));
                    break;
                case 2:
                    startActivity(new Intent(MoreItemsActivity.this, GFActivity.class));
                    break;
                case 3:
                    startActivity(new Intent(MoreItemsActivity.this, EditActivity.class).putExtra("mode", 4).putExtra(
                            "content", "#Android意见反馈#"));
                    break;
                case 4:
                    startActivity(new Intent(MoreItemsActivity.this, AboutActivity.class));
                    break;
                }
            }
        });
    }

    /**
     * The Class MoreItemsAdapter.
     * 
     * @author SunHaibin
     * @since Android 1.6
     * @history 2011-5-31
     */
    class MoreItemsAdapter extends BaseAdapter {

        /**
         * Instantiates a new more items adapter.
         * 
         * @param context1
         *            the context1
         * @param list
         *            the list
         * @param list1
         *            the list1
         */
        public MoreItemsAdapter(Context context1, List list, List list1) {
            // context = context1;
            imageList = list;
            textList = list1;
            LayoutInflater layoutinflater = LayoutInflater.from(context1);
            inflater = layoutinflater;
        }

        /*
         * (non-Javadoc)
         * 
         * @see android.widget.Adapter#getCount()
         */
        @Override
        public int getCount() {
            lastItemPosition = textList.size() - 1;
            return textList.size();
        }

        /*
         * (non-Javadoc)
         * 
         * @see android.widget.Adapter#getItem(int)
         */
        @Override
        public Object getItem(int i) {
            return Integer.valueOf(i);
        }

        /*
         * (non-Javadoc)
         * 
         * @see android.widget.Adapter#getItemId(int)
         */
        @Override
        public long getItemId(int i) {
            return i;
        }

        /*
         * (non-Javadoc)
         * 
         * @see android.widget.Adapter#getView(int, android.view.View,
         * android.view.ViewGroup)
         */
        @Override
        public View getView(int i, View view, ViewGroup viewgroup) {
            ViewHolder viewholder = null;
            int k;
            if (view == null) {
                view = inflater.inflate(R.layout.moreitemsview, null);
                viewholder = new ViewHolder();
                viewholder.textView = (TextView) view.findViewById(R.id.TextView01);
                viewholder.imageView = (ImageView) view.findViewById(R.id.ImageView01);
                viewholder.imageView2 = (ImageView) view.findViewById(R.id.ImageView02);
                view.setTag(viewholder);
            } else {
                viewholder = (ViewHolder) view.getTag();
            }
            viewholder.textView.setText((CharSequence) textList.get(i));
            viewholder.imageView.setImageDrawable(view.getResources().getDrawable((Integer) imageList.get(i)));
            viewholder.imageView2.setImageDrawable(view.getResources().getDrawable(R.drawable.triangle));
            k = lastItemPosition;
            if (i == k) {
                view.setBackgroundResource(R.drawable.circle_list_bottom);
            } else if (i == 0) {
                view.setBackgroundResource(R.drawable.circle_list_top);
            } else {
                view.setBackgroundResource(R.drawable.circle_list_middle);
            }
            return view;
        }

        /** The image list. */
        private final List imageList;

        /** The inflater. */
        private final LayoutInflater inflater;

        /** The last item position. */
        private int lastItemPosition;

        /** The text list. */
        private final List textList;
    }

    /**
     * The Class ViewHolder.
     * 
     * @author SunHaibin
     * @since Android 1.6
     * @history 2011-5-31
     */
    class ViewHolder {

        /** The image view. */
        ImageView imageView;

        /** The image view2. */
        ImageView imageView2;

        /** The text view. */
        TextView textView;
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.yingnet.zhiweibo.HomeListBaseActivity#handleTitleBarEvent(int)
     */
    @Override
    protected void handleTitleBarEvent(int paramInt) {
    }
}